<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <link href="../css/swiper.min.css" rel="stylesheet"/>
    <style>
    .layui-laydate{
      width: 100%!important;
    }.layui-laydate-main{
      width: 100%!important;
    }
    .layui-laydate-content table{
      width: 100%!important;
    }.el-table .cell{
      white-space:pre-line;
      text-align: center;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">库存管理</div>
      </div>
      <!--  -->
      <div class="x-trtali-box" id="calali" style="margin:1rem"></div>
      <!--  -->
      <div class="x-margin-b">

        <template>
          <el-table :data="tabledata" @cell-click="" show-summary>
            <el-table-column label="类别" width="" fixed prop="title">
              <template slot-scope="scope">
                {{scope.row.title}}
              </template>
            </el-table-column>
            <el-table-column label="当日购入" width="" prop="day_buy">
              <template slot-scope="scope">
                {{scope.row.day_buy}}
              </template>
            </el-table-column>
            <el-table-column label="月累计购入" width="" prop="month_buy">
              <template slot-scope="scope">
                {{scope.row.month_buy}}
              </template>
            </el-table-column>
            <el-table-column label="当日调拨" width="" prop="day_allot">
              <template slot-scope="scope">
                {{scope.row.day_allot}}
              </template>
            </el-table-column>
            <el-table-column label="月累计调拨" width="" prop="month_allot">
              <template slot-scope="scope">
                {{scope.row.month_allot}}
              </template>
            </el-table-column>
            <el-table-column label="当日库存" width="" prop="store_num">
              <template slot-scope="scope">
                {{scope.row.store_num}}
              </template>
            </el-table-column>
            <el-table-column label="单品库存" width="">
              <template slot-scope="scope">
                <el-button type="text" @click="opentoast(scope.row.title,scope.row.cateid)">查看</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>


      </div>
      <!--  -->
      <el-dialog :title="toasttitle" :visible.sync="dialogTableVisible" width="90%">
        <el-table :data="gridData">
          <el-table-column label="品名" width="" fixed>
            <template slot-scope="scope">
              {{scope.row.title}}
            </template>
          </el-table-column>
          <el-table-column label="存规格" width="">
            <template slot-scope="scope">
              {{scope.row.save_unit}}
            </template>
          </el-table-column>
          <el-table-column label="当日单价" width="">
            <template slot-scope="scope">
              {{scope.row.unit_price}}
            </template>
          </el-table-column>
          <el-table-column label="购入量" width="">
            <template slot-scope="scope">
              {{scope.row.buy_num}}
            </template>
          </el-table-column>
          <el-table-column label="购入金额" width="">
            <template slot-scope="scope">
              {{scope.row.total_price}}
            </template>
          </el-table-column>
          <el-table-column label="调拨量" width="">
            <template slot-scope="scope">
              {{scope.row.allot_num}}
            </template>
          </el-table-column>
          <el-table-column label="调拨金额" width="">
            <template slot-scope="scope">
              {{scope.row.allot_price}}
            </template>
          </el-table-column>
          <el-table-column label="库存量" width="">
            <template slot-scope="scope">
              {{scope.row.store_num}}
            </template>
          </el-table-column>
          <el-table-column label="库存金额" width="">
            <template slot-scope="scope">
              {{scope.row.store_price}}
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/swiper.min.js"></script>
  <script type="text/javascript" src="../script/laydate/laydate.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          tabsid:0,
          thmonth:'',
          tabsdata:'',
          curId:0,
          tabledata:[],
          toasttitle:'',
          toastid:'',
          dialogTableVisible:false,
          gridData:[],

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        laydate.render({
          elem: '#calali',
          position: 'static',
          btns:['now'],
          format:'yyyyMMdd',
          // theme:'#058142',
          change:function(value,date){
            console.log(value);
            that.thmonth = value;
            that.getdata()
          }
        });
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        var day = date.getDate()
        if(month<10){
          month = '' + 0 + month;
        }
        if(day<10){
          day = '' + 0 + day;
        }
        var toMonth = '' + year +  month +  day;
        that.thmonth = toMonth;
        that.getdata()
      },
      methods: {
        //
        opentoast:function(title,id){
          var that = this;
          that.toasttitle = title;
          that.toastid = id;
          console.log(that.toastid);
          that.dialogTableVisible = true;
          that.gettoast()
        },
        gettoast:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/analyseWhiList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.thmonth,
                cateid:that.toastid,
                _ssid:$api.getStorage('jobid')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.gridData = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        getdata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/analyseWhcList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.thmonth,
                _ssid:$api.getStorage('jobid')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.tabledata = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
